package com.tools.entity;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;

import java.util.ArrayList;
import java.util.List;

public class HttpHeader {
    private List<BasicHeader> headers = new ArrayList<>();

    public HttpHeader addHeader(String name,String value){
        if(StringUtils.isEmpty(name)) return this;
        headers.add(new BasicHeader(name,value));
        return this;
    }
    public Header[] toHeader(){
        return headers.toArray(new BasicHeader[headers.size()]);
    }

    @Override
    public String toString(){
        String str = "";
        for(BasicHeader header:headers){
           str += header.getName()+":"+header.getValue()+",";
        }
        return str;
    }
}
